<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: TT
  Date: 2020/10/16
  Time: 16:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="css/index2.css">
    <script type="text/javascript">
        function del(sid) {
            if (confirm("确定删除这条数据吗？")){
            $.post("del",{"sid":sid},function (num){
                    if (num>0){
                        alert("删除成功");
                    }else {
                        alert("删除失败");
                    }
                location="list";
            },"json")
        }
        }
        //批量删除
        function pls() {
            var a="";
            $(".cc:checked").each(function () {
                a+=","+$(this).val();
            })
            a=a.substring(1);
            del(a);
        }
        //全选全不选
        $(function () {
            $("#f").click(function () {
                $(".cc").prop("checked",$(this).prop("checked"));
            })
        })
        //反选
        function fx() {
            $(".cc").each(function () {
                $(this).attr("checked",!$(this).attr("checked"));
            })
        }
        function up(sid) {
            location="update.jsp?sid="+sid;
        }
    </script>
</head>
<body>
<table>
    <tr>
        <td colspan="10">
            <a href="add.jsp">添加</a>
           <form method="post" action="list">
               电影名称:<input type="text" name="sname" value="${sname}">
               <input type="submit" value="查询">
           </form>
            <input type="button" onclick="pls()" value="批量删除">
            <input type="button" onclick="fx()" value="反选">
        </td>
    </tr>
    <tr>
        <td><input type="checkbox" id="f"></td>
        <td>编号</td>
        <td>电影名称</td>
        <td>电影介绍</td>
        <td>导演名</td>
        <td>发布时间</td>
        <td>电影分类</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${plist.list}" var="a">
        <tr>
            <td><input type="checkbox" class="cc" value="${a.sid}"></td>
            <td>${a.sid}</td>
            <td>${a.sname}</td>
            <td>${a.sinfo}</td>
            <td>${a.daoyan}</td>
            <td>${a.starttime}</td>
            <td>
                <c:forEach items="${a.clist}" var="s">
                    ${s.cname}
                </c:forEach>
            </td>
            <td>
                <input type="button" onclick="del(${a.sid})" value="删除">
                <input type="button" onclick="up(${a.sid})" value="修改">
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="10">
            <a href="list?pageNum=${plist.prePage}">上一页</a>
            <c:forEach begin="1" end="${plist.pages}" step="1" var="num">
                <a href="list?pageNum=${num}">${num}</a>
            </c:forEach>
            <a href="list?pageNum=${plist.nextPage}">下一页</a>
        </td>
    </tr>
</table>

</body>
</html>
